<?php
namespace app\admin\controller;
use app\service\adminService;
use think\facade\Db;
use think\Controller;
use app\service\deviceService;
use app\service\wotuService;
use app\service\iotmcuService;
ini_set('max_execution_time','0');
class Test extends Controller
{
	public function yzl3(){
       $a="1501";
       $b=substr($a,0,2);
       echo $a.$b;
	}
	
	public function test(){
		$userlist=Db::table("personnel")->where("building",6)->where("unit",1)->order('id')->select();
		
		

		foreach ($userlist as $key => $userinfo) {
			if($userinfo["personGuid"]!="0"){
				 //小区大门
		        $locklist1= $locklist=Db::table("device")->where("devicetype",1)->select();
		        
		        $locklist2= Db::table("device")
		                        ->where("devicetype",2)
		                        ->where("building",$userinfo["building"])
		                        ->where("unit",$userinfo["unit"])
		                        ->select();
		        $locklist=array_merge($locklist1,$locklist2);
		        $deviceKeys="";
		        foreach ($locklist as $key => $value) {
		            $deviceKeys=$deviceKeys.$value["devicekey"].",";
		        }
		        $deviceKeys=rtrim($deviceKeys,",");
		        $res=(new wotuService())->accredit($userinfo["personGuid"], $deviceKeys);
		        var_dump($res);echo $userinfo["id"];echo "<br/>";
			}
			
			
	        
		}
		/*
		//查询该小区下的人脸设备并授权
        $locklist=(new deviceService())->userdeviceList($user_id);
        $deviceKeys="";
        if(empty($locklist)){
            return json(["errCode"=>"0",'msg' =>"图片上传成功"]); 
        }
       
        $deviceKeys=rtrim($deviceKeys,",");
        (new wotuService())->accredit($guid, $deviceKeys);*/
	}

	public function test2(){
		//$userlist=Db::table("personnel")->order('id')->limit(500)->select();
		$userlist=Db::table("personnel")->order('id')->limit(500,1000)->select();
		var_dump($userlist);die;
		//$userlist=Db::table("personnel")->order('id')->limit(1000,1500)->select();
		//$userlist=Db::table("personnel")->order('id')->limit(1500,2000)->select();
		//$userlist=Db::table("personnel")->order('id')->limit(2000,2500)->select();
		//$userlist=Db::table("personnel")->order('id')->limit(2500,3000)->select();
		//$userlist=Db::table("personnel")->order('id')->limit(3000,3500)->select();
		//$userlist=Db::table("personnel")->order('id')->limit(4000,4500)->select();
		foreach ($userlist as $key => $userinfo) {
			echo $userinfo["id"];echo "<br/>";
		}
	}
	public function test3(){
		$userlist=Db::table("personnel")->order('id')->limit(1500,100)->select();
		echo "<pre>";
		var_dump($userlist);die;
		foreach ($userlist as $key => $userinfo) {
			if($userinfo["personGuid"]!="0"){
				 //小区大门
		        $locklist1= $locklist=Db::table("device")->where("devicetype",1)->select();
		        
		        $locklist2= Db::table("device")
		                        ->where("devicetype",2)
		                        ->where("building",$userinfo["building"])
		                        ->where("unit",$userinfo["unit"])
		                        ->select();
		        $locklist=array_merge($locklist1,$locklist2);
		        $deviceKeys="";
		        foreach ($locklist as $key => $value) {
		            $deviceKeys=$deviceKeys.$value["devicekey"].",";
		        }
		        $deviceKeys=rtrim($deviceKeys,",");
		        $res=(new wotuService())->accredit($userinfo["personGuid"], $deviceKeys);
		        var_dump($res);echo $userinfo["id"];echo "<br/>";
			}
			
			
	        
		}
	}
}
